local function getFileList(dirname)
	local fileList = os.tmpname()
	os.execute('/usr/bin/find ' .. dirname .. ' -name "*.lua" > ' .. fileList)

	local file = io.open(fileList, "r")
	local content = file:read("*all")

	file:close()
	os.remove(fileList)

	local list = {}
	for line in string.gmatch(content, "[^\n]+") do
		table.insert(list, line)
	end
	return list
end

local function force(file)
	pcall(function() loadfile(file)() end)
end

force("lunit.lua")
force("lunit-console.lua")

-- suit file list, if it is null, find suit files from specified directory
local list = nil -- { "../MockTest.lua" }

-- suit directory, if list is null, find suit files from here
local dirname = "../../../UnitTest/"

if not list then
	list = getFileList(dirname)
end

print("")
for _, file in ipairs(list) do
	print("Test suit file: " .. file)
end
print("")

require "lunit"
require "Mock"

Template.open("../test.db", true)

local stats = lunit.main(list)
if stats.errors > 0 or stats.failed > 0 then
	os.exit(1)
end
